﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.VendorModelCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.VendorModelCommandHandler
{
	/// <summary>
	/// 供应商添加
	/// </summary>
	public class AddVendormodelsCommandHandler : IRequestHandler<AddVendormodelsCommand, Results<int>>
	{
		private readonly IVendorModelService _vendorModelService;
		/// <summary>
		/// 构造方法
		/// </summary>
		/// <param name="vendorModelService"></param>
		public AddVendormodelsCommandHandler(IVendorModelService vendorModelService)
		{
			_vendorModelService = vendorModelService;
		}
		/// <summary>
		/// 供应商添加
		/// </summary>
		/// <param name="request">参数</param>
		/// <param name="cancellationToken"></param>
		/// <returns></returns>
		public async Task<Results<int>> Handle(AddVendormodelsCommand request, CancellationToken cancellationToken)
		{
			var Entity = new Vendormodel()
			{
				BusinessId = request.BusinessId,
				CreateBy = request.CreateBy,
				VendorAttributes = request.VendorAttributes,
				VenDorCode = request.VenDorCode,
				VendorName = request.VendorName,
				VendorDesc = request.VendorDesc,
				VendorType = request.VendorType,
				ArearAdd = request.ArearAdd,
				CreateTime = request.CreateTime,
				IdentityCard = request.IdentityCard,
				IndustryName = request.IndustryName,
				IsDel = request.IsDel,
				Markets = request.Markets,
				Mnemonics = request.Mnemonics,
				ResponsibleName = request.ResponsibleName,
				ResponsiblePhone = request.ResponsiblePhone,
				Salesman = request.Salesman,
				UnifiedSocialCreditCode = request.UnifiedSocialCreditCode,
				UnitsOfReference = request.UnitsOfReference,
				UpdateBy = request.UpdateBy,
				UpdateTime = request.UpdateTime,
				UseState = request.UseState,
			};
			var entity = await _vendorModelService.AddVendormodels(Entity);
			return Results<int>.DataResult(entity);
		}
	}
}
